<html>

<head>
	<meta charset="UTF-8" />
	<meta name="viewport"
		content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title>招聘小程序</title>
	<link rel="stylesheet" href="css/mui.min.css" />
	<!-- build:css css/app.css -->
	<link rel="stylesheet" href="css/base.css" />
	<link rel="stylesheet" href="css/common.css" />
	<!-- endbuild -->
	<style>
		a:active {
			color: #333333;
		}

		.mui-content {
			margin-top: 0;
			margin-bottom: 25px;
			overflow: hidden;
		}

		.header-image {
			width: 100%;
			height: 120px;
			background: url('img/header-image.png') no-repeat center;
			background-size: 100% 100%;
			position: relative;
		}

		.header-image .goback {
			width: 23px;
			height: 23px;
			position: absolute;
			left: 12px;
			top: 12px;
			background: url(img/goback.png) no-repeat;
			background-size: 100%;
		}

		.header-image .share {
			width: 17px;
			height: 17px;
			position: absolute;
			right: 12px;
			top: 12px;
			background: url(img/share.png) no-repeat;
			background-size: 100%;
		}

		.header-image img {
			position: absolute;
			border-radius: 50%;
			width: 60px;
			height: 60px;
			border: 1px solid #fff;
			position: absolute;
			left: 4%;
			bottom: -30px;
		}

		.enterprise {
			margin-bottom: 8px;
			background: #ffffff;
			padding-top: 45px;
		}

		.enterprise-info .enterprise-title {
			margin-bottom: 15px;
			font-size: 20px;
			font-family: arial;
			font-weight: 500;
		}

		.enterprise-tag {
			margin-bottom: 10px;
		}

		.enterprise-tag span {
			padding: 5px 8px;
			margin-right: 8px;
			color: #666666;
			font-size: 14px;
			background: #f7f7f7;
		}

		.enterprise-tag span:last-child {
			margin-right: 0;
		}

		.enterprise-culture {
			padding-bottom: 15px;
			color: #666666;
			font-size: 14px;
		}

		.enterprise-culture a {
			color: var(--blue);
		}
	</style>
</head>

<body id="refreshContainer" style="background: #f1f1f1;">
	<div class="mui-content">
		<div class="header-image">
			<!-- <a class="goback" href="index.html"></a> -->
			<!-- <a class="share"></a> -->
		</div>
		<div class="enterprise">
			<div class="content">
				<div class="enterprise-info">
					<h4 class="enterprise-title"></h4>
					<div class="enterprise-tag">
						<span></span>
						<span></span>
					</div>
					<div class="enterprise-culture">
						<a href="compinfo.html">查看详情</a>
					</div>
				</div>
			</div>
		</div>
		<div class="recruiting">
			<div class="recruiting-title">在招职位</div>
			<div id="position"></div>
		</div>
	</div>
	<div class="navFooter">
		<a href="index.html" id="position" class="cur">
			<i class="c1"></i>首页
		</a>
		<a href="my.html" id="member">
			<i class="c2"></i>我的
		</a>
	</div>
</body>
<script src="js/mui.min.js"></script>
<script src="js/zepto.min.js"></script>
<script src="js/template-web.js"></script>
<!-- build:js js/app.js -->
<script src="js/api.js"></script>
<script src="js/tools.js"></script>
<!-- endbuild -->
<script src="js/utils.js"></script>
<script src="js/jweixin-1.0.0.js"></script>
<script>
	var page = 1;
	// 上拉加载数据
	function loadRecruitment() {
		mui.ajax(config.HOME_API + 'app/listRecruitment', {
			data: {
				compId: getCompId(),
				page: 1,
				limit: 10
			},
			dataType: 'json',
			type: 'post',
			timeout: 10000,
			success: function (res) {
				if (res.code == 2) {
					$('#position').html(template('positions', res.data));
					mui('#refreshContainer').pullRefresh().endPulldownToRefresh(true);
				}
			},
			error: function (xhr, type, errorThrown) {
				mui.toast('网络错误!')
			}
		})
	}
	// 下拉刷新
	function loadDownRecruitment() {
		mui.ajax(config.HOME_API + 'app/listRecruitment', {
			data: {
				compId: getCompId(),
				page: ++page,
				limit: 10
			},
			dataType: 'json',
			type: 'post',
			timeout: 10000,
			success: function (res) {
				if (res.code == 2) {
					$('#position').append(template('positions', res.data));
					setTimeout(function () {
						mui('#refreshContainer').pullRefresh().endPullupToRefresh(true);
					}, 100)
				} else {
					mui.toast(res.msg)
				}
			},
			error: function (xhr, type, errorThrown) {
				mui.toast('网络错误!')
			}
		})
	}
	mui.init({
		pullRefresh: {
			container: '#refreshContainer',//待刷新区域标识，querySelector能定位的css选择器均可，比如：id、.class等
			down: {
				auto: true,
				style: 'circle',
				offset: '0',
				contentdown: "下拉可以刷新",
				contentover: "释放立即刷新",
				contentrefresh: "正在刷新...",
				callback: this.loadRecruitment
			},
			up: {
				height: 0,
				style: 'circle',
				offset: '0',
				contentrefresh: "正在刷新...",
				contentnomore: '没有更多数据了',
				callback: this.loadDownRecruitment
			}
		}
	});
	$(function () {
		function init(comp) {
			var img = document.createElement('img');
			img.className = 'enterprise-logo';
			img.src = comp.logo;
			document.title = comp.name;
			$('.header-image').append(img);
			$('.enterprise-title').text(comp.name);
			$('.enterprise-tag > span:first-child').text(comp.scale + '人');
			$('.enterprise-tag > span:last-child').text(comp.field);
			var introduction = comp.introduction.substring(0, 38).concat('...');
			$('.enterprise-culture').prepend(introduction);
		}
		// 获取企业信息
		mui.ajax(config.HOME_API + 'app/comp', {
			data: {
				compId: getCompId()
			},
			dataType: 'json',
			type: 'post',
			timeout: 10000,
			success: function (res) {
				if (res.code == 2) {
					window.localStorage.setItem('h5_comp', JSON.stringify(res.data.comp));
					window.localStorage.setItem('h5_comp_logo', res.data.comp['logo']);
					var comp = res.data.comp || JSON.parse(localStorage.getItem('h5_comp'));
					init(comp)
				}
			},
			error: function (xhr, type, errorThrown) {
				mui.toast('网络异常!')
			}
		});
		// 微信分享
		$.ajax({
			// url: 'https://king.tongdao.ink/wechatParam?url=' + encodeURIComponent(window.location.href),
			url: 'http://192.168.0.192:8090/app/wechatParam?url=' + encodeURIComponent(window.location.href),
			type: "get",
			datatype: "json",
			async: true,
			timeout: 30000,
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				console.log('进入到error')
				console.log('status:' + XMLHttpRequest.status);
				console.log('readyState:' + XMLHttpRequest.readyState);
				console.log('textStatus:' + textStatus);
				////alert(textStatus);
				// weixinSign()
			},
			success: function (json) {
				if (json.code == '2') {
					console.log(json)
					wx.config({
						debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来
						appId: json.data.appid,
						nonceStr: json.data.nonceStr,
						timestamp: json.data.timestamp,
						signature: json.data.signature,
						jsApiList: [
							"onMenuShareTimeline",//分享朋友圈接口
							"onMenuShareAppMessage",//分享给朋友接口
							"checkJsApi"
						] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
					});

					wx.ready(function () {
						console.log('分享前')
						wx.onMenuShareTimeline({
							title: $('.enterprise-title').text(),
							desc: $('.enterprise-culture').text(),
							link: location.href,
							imgUrl: window.localStorage.getItem("h5_comp_logo"),
							trigger: function (res) {
								// 不要尝试在trigger中使用ajax异步请求修改本次分享的内容，因为客户端分享操作是一个同步操作，这时候使用ajax的回包会还没有返回
								// alert('用户点击发送给朋友');
							},
							success: function (res) {
								console.log('已分享');
							},
							cancel: function (res) {
								console.log('已取消');
							},
							fail: function (res) {
								console.log(JSON.stringify(res));
							}
						});

						wx.onMenuShareAppMessage({
							title: $('.enterprise-title').text(),
							desc: $('.enterprise-culture').text(),
							link: location.href,
							imgUrl: window.localStorage.getItem("h5_comp_logo"),
							trigger: function (res) {
								// 不要尝试在trigger中使用ajax异步请求修改本次分享的内容，因为客户端分享操作是一个同步操作，这时候使用ajax的回包会还没有返回
								// alert('用户点击发送给朋友');
							},
							success: function (res) {
								console.log('已分享');
							},
							cancel: function (res) {
								console.log('已取消');
							},
							fail: function (res) {
								console.log(JSON.stringify(res));
							}
						});
						wx.error(function (res) {
							alert(res.errMsg);
						});
					});
				} else {
					//  alert(json.msg)
				}
			},
			complete: function (XMLHttpRequest, status) {
				if (status == 'timeout') {
					alert("网络异常!");
				}
			}
		});
	})
</script>
<script id="positions" type="text/html">
	<%for(var i = 0; i < list.length; i ++) {%>
	<a href="jobdetails.html?rid=<%=list[i].recruitmentId%>" class="recruiting-list">
		<div class="content">
			<div class="flex-row position-dec">
				<div class="recruiting-position"><%=list[i].positionName%></div>
				<div class="recruiting-money">
					<%=$imports.config.salaryRange[list[i].payMoney]%>
					<% if (list[i].payMoney > 1 && list[i].payMoney < 10) { %>元/月<% } %>
				</div>
			</div>
			<div class="flex-row position-dec">
				<div class="recruiting-claim">
					<%=list[i].cityName%> |
					<%=$imports.config.experience[list[i].experienceRequire]%> |
					<%=$imports.config.edu[list[i].educationRequire]%>
				</div>
				<div class="recruiting-time"><%=$imports.dateFormat(list[i].updateTime, 'M-D')%></div>
			</div>
			<div class="recruiting-tags">
				<% var welfareTreatment =  list[i].welfareTreatment.split(',')%>
				<%for (var j = 0; j < welfareTreatment.length; j ++) {%>
					<% if (list[i].welfareTreatment != '') { %>
						<span><%=$imports.config.welfare[welfareTreatment[j]]%></span>
					<% } else {%>
						<span>暂无福利</span>
					<%} %>
				<%}%>
			</div>
			<p class="recruiting-name"><%=list[i].companyName%></p>
		</div>
	</a>
	<%}%>
</script>

</html>